$(function() {
	var href='';
    $('#tt').tree({
        checkbox: false,
        url: 'js/selectEditTree.json',
        method:'get',
        //查看班级
        onClick: function(node) {
        	if (node.text=='用户管理'){
        		href='page/user/user.jsp'
        	}else if(node.text=='班级管理'){
        		href='page/class/class.jsp'
        	}else if(node.text=='课程管理'){
                href='page/course/course.jsp'
            }else if(node.text=='成绩管理'){
                href='page/score/score.jsp'
            }
                if ($('#tabs').tabs('exists', node.text)) {
                    $('#tabs').tabs('select', node.text);
                } else {
                    var content = '<iframe scrolling="auto" frameborder="0"  src="'+href+'" style="width:100%;height:480px;"></iframe>';
                    $('#tabs').tabs('add', {
                        title:  node.text,
                        content: content,
                        closable: true
                    });
                }
        }
    });
    
    $('#student').tree({
        checkbox: false,
        method:'get',
        url: 'js/student.json',
        //查看班级
        onClick: function(node) {
            if (node.text=='个人信息'){
                href='page/personInfo/personInfo.jsp'
            }else if(node.text=='班级信息'){
                href='page/classInfo/classInfo.jsp'
            }else if(node.text=='成绩查询'){
                href='page/scoreQuery/scoreQuery.jsp'
            }
                if ($('#tabs').tabs('exists', node.text)) {
                    $('#tabs').tabs('select', node.text);
                } else {
                    var content = '<iframe scrolling="auto" frameborder="0"  src="'+href+'" style="width:100%;height:480px;"></iframe>';
                    $('#tabs').tabs('add', {
                        title:  node.text,
                        content: content,
                        closable: true
                    });
                }
        }
    });
    //用户信息设置
    $('#set').click(function(){
        if ($('#setWindow')[0]==null) {
            $('<div id="setWindow"></div>').appendTo($('body'));
        }
    	$('#setWindow').dialog({    
        title: '设置',    
        width: 300,    
        height: 350,    
        closed: false,    
        cache: false,       
        modal: true,
        href:'page/user/setUser.jsp',
            buttons:[{
                text:'保存',
                iconCls : 'icon-save',
                handler:function(){
                    if (!$('#setUserForm').form('validate')) {
                        return;
                    }
                    var setUser = $('#setUserForm').serialize();
                    $.post('updateBaseUser.action',setUser, function(data) {
          
                        if (data.returnmsg =='success') {
                            alert('更新成功')
                            $('#setWindow').dialog('destroy');
                            $('#dg').datagrid('reload');  
                        } else {
                            alert('更新失败');
                            $('#setWindow').dialog('destroy');
                        }
                    })
                }
            },{
                text:'取消',
                iconCls : 'icon-undo',
                handler:function(){
                    $('#setWindow').dialog('destroy');
                }
            }]
    }); 
    	$.post('user_getYourself.action','',function(data){
    		$('#nicename2').val(data[0].niceName);
    		$('#username2').val(data[0].username);
    		$('#phone2').val(data[0].phone);
    		$('#email2').val(data[0].email);   		
    	});
    }) 
});
